package com.best.intelligentTrolley

import android.os.Bundle
import android.widget.ImageButton
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.blankj.utilcode.util.SPUtils
import com.blankj.utilcode.util.TimeUtils
import java.util.*
import kotlin.concurrent.timer

class InfoActivity : AppCompatActivity() {


    private var timeTimer: Timer? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_info)

        val tv_date = findViewById<TextView>(R.id.tv_date)
        val ibtn_return = findViewById<ImageButton>(R.id.ibtn_return)
        val tv_factory_no = findViewById<TextView>(R.id.tv_factory_no)
        val tv_panel_version = findViewById<TextView>(R.id.tv_panel_version)
        val tv_soft_version = findViewById<TextView>(R.id.tv_soft_version)
        val tv_plasma_life = findViewById<TextView>(R.id.tv_plasma_life)
        val tv_company_name = findViewById<TextView>(R.id.tv_company_name)
        val tv_company_tel = findViewById<TextView>(R.id.tv_company_tel)
        val tv_company_address = findViewById<TextView>(R.id.tv_company_address)
        
        tv_date.text = TimeUtils.millis2String(System.currentTimeMillis(), TimeUtils.getSafeDateFormat("MM/dd HH:mm"))

        tv_factory_no.text = "出厂编号：${SPUtils.getInstance().getString("factory_no")}"
        tv_company_name.text = "公司名称：${SPUtils.getInstance().getString("company_name")}"
        tv_company_tel.text = "客服电话：${SPUtils.getInstance().getString("company_tel")}"
        tv_company_address.text = "公司地址：${SPUtils.getInstance().getString("company_address")}"
        tv_soft_version.text = "软件版本号：${packageManager.getPackageInfo(packageName,0).versionName}"
        tv_panel_version.text = "主控版本号：${App.instance.zkVersion}"
        tv_plasma_life.text = "等离子体发生器剩余寿命：${Config.getPlasmaModulePeriodOfValidity()}"

        ibtn_return.setOnClickListener {
            finish()
        }

        timeTimer = timer(null, false, 1000L, 1000L) {
            runOnUiThread {
                tv_date.text = TimeUtils.millis2String(System.currentTimeMillis(), TimeUtils.getSafeDateFormat("MM/dd HH:mm"))
            }
        }

    }

    override fun onDestroy() {
        super.onDestroy()
        timeTimer?.cancel()
    }
}